/************************************************************
* @file gkt_i2c.h
************************************************************/

#ifndef GKT_I2C_H
#define GKT_I2C_H

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum _gkt_i2c_addr {
	GKT_I2C_ADDR_7BITS = 0,
	GKT_I2C_ADDR_10BITS,
	GKT_I2C_ADDR_INVALID
} gkt_i2c_addr_e;

typedef enum _gkt_i2c_speed {
	GKT_I2C_SPEED_STANDARD = 1,	/* <= 100 kbit/s */
	GKT_I2C_SPEED_FAST,	/* <=400 kbit/s */
	GKT_I2C_SPEED_FAST_PLUS,	/* <= 800Kbit/s */
	GKT_I2C_SPEED_HIGH,	/* <= 1.4 Mbit/s */
	GKT_I2C_SPEED_INVALID
} gkt_i2c_speed_e;

typedef struct _gkt_i2c_config_params {
	uint16_t	target_addr;	/* 7bits/10bits target address */
	gkt_i2c_addr_e	addr_bits;
	gkt_i2c_speed_e	speed;
	int	restart_enable;
} gkt_i2c_config_params_s;

int gkt_i2c_init(void);

/************************************************************
 * @function  gkt_i2c_open
 * @brief     open an i2c object
 * @params
 *   dev_id   [in] i2c device id (0, ..., DEV_MAXNUMS - 1)
 * @return
 *   not-NULL : success, i2c object handle
 *   NULL     : failed
 ************************************************************/
gkt_handle_t gkt_i2c_open(int master,
							uint32_t dev_id, uint32_t slave_id);

int gkt_i2c_close(gkt_handle_t handle);

int gkt_i2c_config(gkt_handle_t handle, 
			gkt_i2c_config_params_s *params);

/************************************************************
 * @function  gkt_i2c_master_receive
 * @brief     master receive
 * @params    
 *   handle          [in] i2c object handle
 *   target_addr	 [in] 7bits/10bits target address 
 *   buffer          [in] buffer to store received bytes
 *   to_receive_size [in] to receive size
 *   received_size   [out] [optional] received size
 *   timeout         [in] receive operation timeout, unit in ms
 * @return
 *   0   : success, to_receive_size == received_size
 *   < 0 : error occurs, to_receive_size < received_size
 ************************************************************/
int gkt_i2c_master_receive(gkt_handle_t handle,
				void *buffer, uint32_t to_receive_size, 
				uint32_t *received_size, uint32_t timeout);

int gkt_i2c_master_send(gkt_handle_t handle,
			const void *data, uint32_t to_send_size, 
			uint32_t *sent_size, uint32_t timeout);

int gkt_i2c_master_transmit(gkt_handle_t handle,
			const void *send_data, uint32_t to_send_size,
			uint32_t *sent_size, 
			void *receive_data, uint32_t to_receive_size, 
			uint32_t *received_size, uint32_t timeout);

#ifdef __cplusplus
}
#endif

#endif	/* GKT_I2C_H */

